const PageView = {
  dialogValidate: null,
  init: () => {
    const nDate = PageView.getCurrDate();
    $('#datepicker').datepicker('setValue', nDate).datepicker('place')
    $('#dateTime').datepicker('setValue', nDate)
    PageView.dialogValidate = $('#dialog-validate-confirm')
    PageView.dialogValidate.modal({
      relatedTarget: this,
      closeViaDimmer: 1,
      onConfirm: function(e) {PageView.dialogValidate.modal('close')}
    }).modal('close')
    $('#btnSubmit').on('click', PageView.submit)
  },
  submit: async () => {
    const dir = $('#btnSelectImagesDir').attr('dir-path')
    if (!dir) {
      return PageView.showValidateDialog('请选择图片文件夹')
    }
    const file = $('#doc-form-file').val()
    if (!file) {
      return PageView.showValidateDialog('请选择Excel文件')
    } else if (file.substr(-4) !== 'xlsx') {
      return PageView.showValidateDialog('Excel文件格式有误')
    }
  },
  showValidateDialog: (txt) => {
    $('#tip-txt').text(txt)
    PageView.dialogValidate.modal('open')
  },
  getCurrDate: () => {
    const date = new Date();
    const year = date.getFullYear();
    const month = date.getMonth() + 1;
    const day = date.getDate();
    return `${year}-${month < 10 ? `0${month}` : month}-${month < 10 ? `0${day}` : day}`;
  }
}
$(function() {
  PageView.init()
})